Wait for device name to appearr before mount, mkfs
authorHilko Bengen <bengen@debian.org>
Sat, 3 Jan 2026 14:05:07 +0000 (15:05 +0100)
committerHilko Bengen <bengen@debian.org>
Sun, 8 Feb 2026 12:36:00 +0000 (13:36 +0100)
Gbp-Pq: Name Wait-for-device-name-to-appearr-before-mount-mkfs.patch

daemon/mkfs.c
daemon/mount.ml

index fe2e6781b35852d647a30d148135dc33e2610679..66c937bed41f4949c93b1ea213d3d590d8201112 100644 (file)
@@ -52,6 +52,14 @@ do_mkfs (const char *fstype, const char *device, int blocksize,
   CLEANUP_FREE char *err = NULL;
   int extfs = 0;
 
+  /* Wait up to 15s for device to appear */
+  for (int j=0; i < 150; i++) {
+    if (!access (device, F_OK)) {
+      break;
+    }
+    usleep(100000);
+  }
+
   if (fstype_is_extfs (fstype))
     extfs = 1;
 
index 171bea105d51fae6d392922e39d2bff7c0fb3071..2f74555d629a4ff4af2b4780fed619e1b22014c9 100644 (file)
@@ -30,6 +30,18 @@ let mount_vfs options vfs mountable mountpoint =
 
   let args = ref [] in
 
+  (* Wait up to 15s for device to appear *)
+  (match mountable.m_type with
+  | MountableDevice | MountablePath ->
+    if String.starts_with "/dev/" mountable.m_device then
+      let i = ref 0 in
+      while (not (Sys.file_exists mountable.m_device)) && (!i < 150) do
+        Unix.sleepf 0.1;
+        i := !i + 1;
+      done
+  | _ -> ()
+  );
+
   (* -o options *)
   (match options, mountable.m_type with
    | "", (MountableDevice | MountablePath) -> ()